package com.terrace.db.system.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.terrace.db.constant.DBType;
import com.terrace.db.system.dao.IconDao;
import com.terrace.db.system.mapper.entity.Icon;
import com.terrace.db.system.service.IconService;
import com.terrace.core.mybatis.entity.Pagination;
import com.terrace.core.mybatis.plugin.pagination.PaginationHelper;
import com.terrace.core.spring.datasource.annotation.DataSource;
import com.terrace.core.spring.ehcache.annotation.EhCacheEvict;
import com.terrace.core.spring.ehcache.annotation.EhCacheable;

@Service
@Transactional
@DataSource(name = DBType.ADMIN)
public class IconServiceImpl implements IconService {
	
	@Autowired
	private IconDao iconDao;

	@Override
	@EhCacheEvict(key = "selectIconByCode")
	public int insertIconSelective(Icon icon) {
		return iconDao.insertIconSelective(icon);
	}

	@Override
	@EhCacheEvict(key = "selectIconByCode")
	public int deleteIconById(String iconId) {
		return iconDao.deleteIconById(iconId);
	}

	@Override
	@EhCacheEvict(key = "selectIconByCode")
	public int updateIconSelectiveById(Icon icon) {
		return iconDao.updateIconSelectiveById(icon);
	}

	@Override
	public Icon selectIconById(String iconId) {
		return iconDao.selectIconById(iconId);
	}
	
	@Override
	@EhCacheable(key = "selectIconByCode")
	public Icon selectIconByCode(String iconCode) {
		return iconDao.selectIconByCode(iconCode);
	}

	@Override
	public Pagination<Icon> selectIconForPagination(Pagination<Icon> pagination, Icon icon) {
		PaginationHelper.prepare(pagination);
		return PaginationHelper.execute(iconDao.selectIconForPagination(icon));
	}

}
